import 'package:flutter/cupertino.dart';
import 'package:flutter_app/bindings/girl_bindings.dart';
import 'package:flutter_app/bindings/login_bindings.dart';
import 'package:flutter_app/compents/web_page.dart';
import 'package:flutter_app/defualt/Global.dart';
import 'package:flutter_app/page/girl/girls_page.dart';
import 'package:flutter_app/page/login/index_page.dart';
import 'package:flutter_app/page/login/login_page.dart';
import 'package:flutter_app/page/login/login_page_bubbles.dart';
import 'package:flutter_app/page/photoview/photo_view_page.dart';
import 'package:flutter_app/page/splash/splash_page.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/routes/get_route.dart';
import 'package:get/get_navigation/src/routes/route_middleware.dart';

abstract class RoutesConfig {
  static const SPLASH = "/";
  static const MAIN = "/main";
  static const LOGIN_PAGE = "/login";
  static const LOGIN_PAGE_BUBBLES = "/login/bubbles";
  static const REGISTER_PAGE = "/register";
  static const SETTING_PAGE = "/setting_page";
  static const GIRL_PAGE = "/girl_page";
  static const WEB_PAGE = "/web_page";
  static const NEWS_LIST_PAGE = "/news_list_page";
  static const MESSAGE_LIST_PAGE = "/person/message_list_page";
  static const PERSON_COLLECTION_PAGE = "/person/person_collection_page";
  static const PERSON_SHARE_PAGE = "/person/person_share_page";
  static const PERSON_STARTS_PAGE = "/person/person_stars_page";
  static const STARTS_LEADERBOARD_PAGE = "/person/starts_leaderboard_page";
  static const PHOTO_VIEW = "/photo/view";
  static final List<GetPage> getPages = [
    GetPage(
      name: SPLASH,
      page: () => SplashPage(),
    ),
    GetPage(
        name: LOGIN_PAGE,
        page: () => LoginPage(),
        bindings: [
          LoginBindings(),
        ],
        transition: Transition.downToUp),
    GetPage(name: MAIN, page: () => IndexPage(), bindings: [
      // ArticleCollectionBindings(),
      // RegisterBindings(),
      // SearchBindings(),
    ]),
    GetPage(name: GIRL_PAGE, page: () => GirlsPage(), binding: GirlBindings()),
    GetPage(name: LOGIN_PAGE_BUBBLES, page: () => BobbleLoginPage()),
    GetPage(
        name: PHOTO_VIEW,
        page: () => PhotoViewMultiple(),
        transition: Transition.topLevel),
    GetPage(name: WEB_PAGE, page: () => WebPage()),
  ];
}

///路由跳转的中间鉴权，需要登录后才能访问的页面
class RouteAuthMiddleware extends GetMiddleware {
  @override
  RouteSettings redirect(String route) {
    //没有登录过，就需要去登录页面
    if (!Global.isUserOnLine) {
      return RouteSettings(name: RoutesConfig.LOGIN_PAGE);
    }
    //登录过，就不要拦截正常跳转到目标页面。
    return null;
  }
}
